package com.deer.wms.base.system.web.box;

import com.deer.wms.base.system.model.bar.BarCode;
import com.deer.wms.base.system.model.bar.BarCodeDto;
import com.deer.wms.base.system.model.box.BoxItemBacth;
import com.deer.wms.base.system.service.box.BoxItemBacthService;
import com.deer.wms.common.core.controller.BaseController;
import com.deer.wms.common.core.domain.AjaxResult;
import com.deer.wms.common.core.page.TableDataInfo;
import com.deer.wms.framework.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/boxItembacth")
public class BoxItemBacthController extends BaseController {
    @Autowired
    private BoxItemBacthService boxItemBacthService;
    private String prefix="system/boxItembacth";

    /**
     *跳转显示页面
     * @return
     */
    @RequiresPermissions("system:boxItembacth:view")
    @GetMapping("/page")
    public String BarCode()
    {
        return prefix + "/boxItembacth";
    }

    /**
     * 显示全部信息
     * @param boxItemBacth
     * @return
     */
    @RequiresPermissions("system:boxItembacth:list")
    @PostMapping("/findList")
    @ResponseBody
    @Transactional
    public TableDataInfo findList(BoxItemBacth boxItemBacth) {
        startPage();
        List<BoxItemBacth> list = boxItemBacthService.findBoxItemBacthList(boxItemBacth);
        return getDataTable(list);
    }
    /**
     * 新增跳转页面
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增
     * @param boxItemBacth
     * @return
     */
    @RequiresPermissions("system:boxItembacth:add")
    @PostMapping("/insert")
    @ResponseBody
    @Transactional
    public AjaxResult insert( BoxItemBacth boxItemBacth){
        String createUserName = ShiroUtils.getLoginName();
        Integer userId = ShiroUtils.getUserId();
        boxItemBacth.setCreateUserId(userId);
        boxItemBacth.setCreateUserName(createUserName);
        return toAjax(boxItemBacthService.saveBoxItemBacth(boxItemBacth));
    }
    /**
     * 删除
     * @param ids
     * @return
     */
    @RequiresPermissions("system:boxItembacth:remove")
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids){
        return toAjax(boxItemBacthService.delectBoxItemBacthByIds(ids));
    }
    /**
     * 修改跳转页面
     */
    @GetMapping("/edit/{batchId}")
    public String edit(@PathVariable("batchId") Integer batchId, ModelMap mmap)
    {
        BoxItemBacth boxItemBacth= boxItemBacthService.findBoxItemBacthById(batchId);
        mmap.put("boxItemBacth", boxItemBacth);
        return prefix+"/edit";
    }

    /**
     * 修改保存
     * @param boxItemBacth
     * @return
     */
    @RequiresPermissions("system:boxItembacth:edit")
    @PostMapping("/edit")
    @ResponseBody
    @Transactional
    public AjaxResult editSave(BoxItemBacth boxItemBacth){
        String createUserName = ShiroUtils.getLoginName();
        Integer userId = ShiroUtils.getUserId();
        boxItemBacth.setCreateUserId(userId);
        boxItemBacth.setCreateUserName(createUserName);
        return toAjax(boxItemBacthService.UpdateBoxItemBacth(boxItemBacth));
    }
}
